<!DOCTYPE html>
<html>
  
  <head>
      <meta charset="UTF-8">
      <title>欢迎页面-X-admin2.0</title>
      <meta name="renderer" content="webkit">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
      <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
      <link rel="stylesheet" href="/static/css/font.css">
      <link rel="stylesheet" href="/static/css/xadmin.css">
      <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
      <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
      <script type="text/javascript" src="/static/js/xadmin.js"></script>
      <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
      <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
      <![endif]-->

      <link rel="stylesheet" href="/static/sweetalert/sweetalert.css">
      <script src="/static/sweetalert/ions_alert.js"></script>
      <script src="/static/sweetalert/sweetalert.min.js"></script>
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>车辆品牌名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="brand_name" name="brand_name" lay-verify="category_name"
                  autocomplete="off" class="layui-input" value="{{.cars_brand.BrandName}}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>(必填)
              </div>
          </div>

            <div class="layui-form-item">
                <label for="desc" class="layui-form-label">
                    <span class="x-red">*</span>车辆品牌描述
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="brand_desc" name="brand_desc" lay-verify="desc"
                           autocomplete="off" class="layui-input" value="{{.cars_brand.BrandDesc}}">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_is_active" class="layui-form-label">
                    <span class="x-red">*</span>启用状态
                </label>
                <div class="layui-input-inline">
                    {{if eq .cars_brand.IsActive 1}}
                        <input type="radio" name="is_active" autocomplete="off" class="layui-input" value="1" title="启用" checked>

                        <input type="radio" name="is_active" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="0" title="停用">
                    {{else if eq .cars_brand.IsActive 2}}
                        <input type="radio" name="is_active" autocomplete="off" class="layui-input" value="1" title="启用">

                        <input type="radio" name="is_active" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="0" title="停用" checked>
                    {{end}}
                </div>
            </div>

          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
{{/*              <input type="hidden" id="sys_id"  value="{{.user.SysId}}">*/}}
              <input type="hidden" value="{{.cars_brand.SysId}}" id="car_brand_id">
              <button  class="layui-btn" lay-filter="add" lay-submit type="button">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script>
        function reload_list() {
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            window.parent.location.reload(); //刷新父页面
            //关闭当前frame
            parent.layer.close(index);
            window.location.href = "{{urlfor "CarBrandController.List"}}"
        }

            $(function  () {
                layui.use('form', function () {
                    var form = layui.form;
                    //监听提交
                    form.on('submit(add)', function (data) {
                        // nickname 用的是 id="nickname"
                        var brand_name = document.getElementById("brand_name").value;
                        var brand_desc = document.getElementById("brand_desc").value;
                        var is_active = $("input[name='is_active']:checked").val();
                        var sys_id = document.getElementById("car_brand_id").value;

                        $.ajax({
                            url:"{{urlfor "CarBrandController.DoEdit"}}",
                            type:"POST",
                            data:{
                                "brand_name":brand_name,
                                "brand_desc":brand_desc,
                                "sys_id":sys_id,
                                "is_active":is_active
                            },
                            success:function (data) {
                                var code = data["code"];
                                if (code == 200){
                                    ions_alert.alertSuccessToast(data["msg"]);
                                     setTimeout(reload_list,2000);  // 2s 显示时间2秒后刷新list页面
                                }else {
                                    ions_alert.alertErrorToast(data["msg"]);
                                }
                            },
                            fail:function (data) {
                                alert(data)
                            }
                        });

                    });
                });
          
        })

    </script>
  </body>

</html>